package com.smcad.gsm.view;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import android.location.Address;
import android.location.Geocoder;

import com.google.android.maps.GeoPoint;
import com.smcad.gsm.Main;

/** Class to hold our location information */
public class MapLocation {

	private GeoPoint point;
	public String address;
	public String title;
	public String description;
	
	public MapLocation(String title, String address, String description) {
		this.title = title;
		this.address = address;
		this.description = description;
		
		Geocoder geoCoder = new Geocoder(Main.getContext(), Locale.getDefault());    
        try {
            List<Address> addresses = geoCoder.getFromLocationName(
            		this.address, 5);
            if (addresses.size() > 0) {
            	
            	point = new GeoPoint(
                        (int) (addresses.get(0).getLatitude() * 1E6), 
                        (int) (addresses.get(0).getLongitude() * 1E6));
            	
            }   
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	
	public String toString() {
		return "title: " + title + "\n" +
			   "address: " + address + "\n" +
			   "description: " + description + "\n" +
			   "point: " + point + 
			   "\n----------------------\n";
	}

	public GeoPoint getPoint() {
		return point;
	}

	public void setPoint(GeoPoint point) {
		this.point = point;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
}
